package com.hzhr.iot.meterplan.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.meterplan.controller.base.BaseController;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanGetModel;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanModel;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanPostModel;
import com.hzhr.iot.meterplan.model.meterPlan.MeterPlanPutModel;
import com.hzhr.iot.meterplan.service.MeterPlanService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "MeterPlan", description = "抄表计划")
@RestController
@RequestMapping(value = "")
public class MeterPlanController extends BaseController {
    @Autowired
    MeterPlanService meterPlanService;

    //region /meter-plans GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="查询登录用户管辖范围下的远传表抄表计划", notes="查询登录用户管辖范围下的远传表抄表计划  \n1. 查询抄表计划：查询登录用户管辖范围下的远传表抄表计划(按抄表计划编号降序排列)  \n2. 返回信息  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件：where MeterPlanModel.id = #{equal_id}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "like_des", value = "筛选条件：where MeterPlanModel.des like % + #{like_des} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_typeId", value = "筛选条件：where MeterPlanModel.typeId = #{equal_typeId}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_statusId", value = "筛选条件：where MeterPlanModel.statusId = #{equal_statusId}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_equal_id", value = "筛选条件：where MeterPlanModel.id = #{_equal_id}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_like_des", value = "筛选条件：where MeterPlanModel.des like % + #{_like_des} + %", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_typeId", value = "筛选条件：where MeterPlanModel.typeId = #{_equal_typeId}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_statusId", value = "筛选条件：where MeterPlanModel.statusId = #{_equal_statusId}", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_page", value = "页数", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_count", value = "每页数量", defaultValue = "1",required = false, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_total", value = "是否展示总数", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),
    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/meter-plans", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<MeterPlanGetModel> get(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        MeterPlanGetModel responseBody = meterPlanService.get(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

    //region /meter-plans POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="创建抄表计划", notes="创建抄表计划  \n1.新增状态为待执行的抄表计划；  \n2.返回信息；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : post
    @RequestMapping(value = "/meter-plans", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<MeterPlanGetModel> post(@RequestParam @ApiIgnore Map<String, Object> query,
                                                  @RequestBody MeterPlanPostModel body) throws ServiceException {
        MeterPlanGetModel responseBody = meterPlanService.post(initHeader(), query,body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

    //region /meter-plans/{meterPlanId} PUT
    //region swagger响应码 : put
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : put
    @ApiOperation(value="更新抄表计划", notes="更新抄表计划  \n1.更新抄表计划信息；  \n2.返回信息；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : put
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "meterPlanId", value = "meterPlanId",required = true, dataType = "string", paramType = "path"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : put
    @RequestMapping(value = "/meter-plans/{meterPlanId}", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<MeterPlanGetModel> put(@RequestParam @ApiIgnore Map<String, Object> query,
                                                 @PathVariable String meterPlanId,
                                                 @RequestBody MeterPlanPutModel body) throws ServiceException {
        MeterPlanGetModel responseBody = meterPlanService.put(initHeader(),query,meterPlanId,body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
    }
    //endregion

}
